#include "Menu.h"
#include "../Charecter/ChDraw.h"
#include "../States/State.h"
#include <pspctrl.h>

unsigned char m_menu[MENU_COUNT][MENU_ITEM_LEN] = {
	"NEW FILE\0",
	"OPEN FILE\0",
	"DELETE FILE\0",
	};

int m_menu_state_dir[MENU_COUNT] = {NEW_FILE, OPEN_FILE, DELETE_FILE};
	

void InitMenu()
{
	m_selected = 1;
}

void DrawMenu(int x, int y)
{
	int i;
	for(i = 0; i< MENU_COUNT; i++)
	{
		DrawString(x, y + i * (MENU_ITEM_SPACE + FONT_HEIGHT), m_menu[i], MENU_ITEM_LEN, (m_selected==i)?MENU_ITEM_SELECTED_COLOR:MENU_ITEM_COLOR, 1);
	}
}

void UpdateMenu()
{
	if(IsPressed(PSP_CTRL_UP))
	{
			m_selected--;
			if(m_selected<0)
				m_selected = 0;
	}
	if(IsPressed(PSP_CTRL_DOWN))
	{
			m_selected++;
			if(m_selected>=MENU_COUNT)
				m_selected = MENU_COUNT-1;
	}
	if(IsPressed(PSP_CTRL_CIRCLE))
	{
		switch(m_menu_state_dir[m_selected])
		{
			case NEW_FILE:
				memset(txtbuffer, 0, BUFFER_SIZE);
				txtlen = 0;
				SetState(STATE_INITNOTPAD);
				break;
			case OPEN_FILE:	
				SetState(STATE_FILEIO);	
				break;
			case DELETE_FILE:	
				SetState(STATE_FILEIO);	
				break;				
		}
	}
}

void DrawSave()
{
	
}

void UpdateSave()
{
	
}

